package com.travel.photos.ui.travel;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.travel.R;
import com.travel.photos.base.BaseFragment;

import butterknife.Bind;
import tools.EndLessOnScrollListener;

/**
 * Created by meidou on 2016/10/18.
 * 发现的fragment
 */
public class PhotoVpTravelFragment extends BaseFragment implements TravelContract.View{
    @Bind(R.id.photot_recycle)
    RecyclerView mPhototRecycle;
    @Bind(R.id.photo_swp)
    SwipeRefreshLayout mPhotoSwp;
    private LinearLayoutManager mManager;
    private TravelPresenter mPresenter;
    @Override
    public void getDetail(TravelAdapter adapter) {
        mPhototRecycle.setAdapter(adapter);
        mPhotoSwp.setRefreshing(false);
    }

    @Override
    protected void initData() {
        mPresenter = new TravelPresenter(this);
        mPresenter.getDetail(getActivity());
    }

    @Override
    protected void initView() {
        mManager = new LinearLayoutManager(getContext());
        mManager.setOrientation(LinearLayoutManager.VERTICAL);
        mPhototRecycle.setLayoutManager(mManager);
        mPhototRecycle.setItemAnimator(new DefaultItemAnimator());
        //下拉刷新
        mPhotoSwp.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
            mPresenter.DownRefresh(getContext());
            }
        });
        //上拉加载
        mPhototRecycle.addOnScrollListener(new EndLessOnScrollListener(mManager) {
            @Override
            public void onLoadMore(int currentPage) {
                mPresenter.UpRefresh(getContext());
            }
        });
    }
    @Override
    protected int getLayoutId() {
        return R.layout.photo_vp_find;
    }
}
